package in.ac.dei.edrp.cms.controller.sendpassword;

import in.ac.dei.edrp.cms.dao.sendpassword.SendPasswordService;
import in.ac.dei.edrp.cms.domain.sendpassword.SendPasswordInfoGetter;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

public class SendPasswordController extends MultiActionController {
	private SendPasswordService sendPasswordService;
	
	public void setSendPasswordService(SendPasswordService sendPasswordService) {
		this.sendPasswordService = sendPasswordService;
	}

	public ModelAndView sendEmail(HttpServletRequest request,HttpServletResponse response){
		List<SendPasswordInfoGetter> li=sendPasswordService.getUserList();
		
		Boolean bool=true;
		for(int i=0;i<li.size();i++)
		{
			bool=sendPasswordService.setApplicantUserInfo(li.get(i))&&bool;
		}
		if(bool)
		{
			return new ModelAndView("sendpassword/accountInfo","info","Mail Sent successfully.");
		}else
		{
			return new ModelAndView("sendpassword/accountInfo","info","Mail Not Sent.");
		}
	}

	public ModelAndView activateAccount(HttpServletRequest request,HttpServletResponse response){
		SendPasswordInfoGetter sendPasswordInfoGetter=new SendPasswordInfoGetter();
		sendPasswordInfoGetter.setUniversityId(request.getParameter("UI"));
		sendPasswordInfoGetter.setUserId(request.getParameter("userId"));
		sendPasswordInfoGetter.setAIorUI(request.getParameter("AIUI"));
		Integer i=sendPasswordService.updateAIUIStatus(sendPasswordInfoGetter);
		if(i>0)
		{
			return new ModelAndView("sendpassword/accountInfo","info","Account activated successfully.");
		}
		else
		{
			return new ModelAndView("sendpassword/accountInfo","info","Page Expired.");
		}
	}
	
}
